import {Injectable} from '@angular/core';
import {HttpService} from '../http.service';
import {adSystemApiUrl} from '../../../../config/api';

@Injectable()

export class PermissionService {

    constructor(
        private httpService: HttpService
    ) {}

    /**
     * 权限列表
     * @param name
     * @param model
     * @param orderField
     * @param orderSort
     * @param pageSize
     * @returns {Observable<R>}
     */
    getPermissionList(name, model, orderField, orderSort, page, pageSize) {
        const url = `${ adSystemApiUrl }/v1/admin/permissions/list?name=${ name }&model=${ model }&orderField=${ orderField }&orderSort=${ orderSort }&page=${ page }&pageSize=${ pageSize }`;
        return this.httpService.httpGetAuth(url).map(data => data);
    }

    /**
     * 权限详情
     * @param id
     * @returns {Observable<R>}
     */
    getPermissionInfo(id) {
        const url = `${ adSystemApiUrl }/v1/admin/permissions/${ id }/info`;
        return this.httpService.httpGetAuth(url).map(data => data);
    }

    /**
     * 权限添加
     * @param data
     * @returns {Observable<R>}
     */
    addPermission(data) {
        const url = `${ adSystemApiUrl }/v1/admin/permissions/add`;
        return this.httpService.httpPostAuth(url, data).map(data => data);
    }

    /**
     * 权限修改
     * @param data
     * @returns {Observable<R>}
     */
    editPermission(data) {
        const url = `${ adSystemApiUrl }/v1/admin/permissions/edit`;
        return this.httpService.httpPostAuth(url, data).map(data => data);
    }

    /**
     * 权限删除
     * @param id
     * @returns {Observable<R>}
     */
    delPermission(id) {
        const url = `${ adSystemApiUrl }/v1/admin/permissions/${ id }/del`;
        return this.httpService.httpPostAuth(url, null).map(data => data);
    }
}